package com.gitee.wsl.ext.db

import androidx.room.RoomDatabase

open class WarpDao<V,T:BaseDao<V>,D: RoomDatabase>(private val delegate:T, private val db:D):BaseDao<V> by delegate {

    fun query(block: T.() -> Unit) = with(db) {
        block(delegate)
    }

    suspend fun transaction(block: T.() -> Unit) = with(db) {
        withTransaction {
            block(delegate)
        }
    }
}

/**
 * class MusicDatabase(
 *     private val delegate: InternalDatabase,
 * ) : DatabaseDao by delegate.dao {
 *     val openHelper: SupportSQLiteOpenHelper
 *         get() = delegate.openHelper
 *
 *     fun query(block: MusicDatabase.() -> Unit) = with(delegate) {
 *         queryExecutor.execute {
 *             block(this@MusicDatabase)
 *         }
 *     }
 *
 *     fun transaction(block: MusicDatabase.() -> Unit) = with(delegate) {
 *         transactionExecutor.execute {
 *             runInTransaction {
 *                 block(this@MusicDatabase)
 *             }
 *         }
 *     }
 *
 *     fun close() = delegate.close()
 * }
 */